<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script type="text/javascript" src="./js/abkj/match/api/signview.js"></script>
	<script type="text/javascript" src="./js/abkj/ext/signExt.js"></script>
	<script type="text/javascript" src="./js/abkj/ext/matchExt.js"/></script>
	<script type="text/javascript" src="./js/abkj/match/api/grade.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/importadvanceview.js"></script>

	<script type="text/javascript" src="./js/abkj/match/api/scheduletype.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/tmatch.js"/></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
			<a href="">首页</a>
			<a><cite>比赛管理</cite></a>
			<a><cite>晋级管理</cite></a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
		<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
	</a>
</div>
<div class="layui-fluid" id="content">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-body ">
					<form class="layui-form layui-col-space5 flex" style="display: flex;">
						<!--<div class="layui-input-inline layui-show-xs-block">-->
						<!--<input class="layui-input" placeholder="开始日" name="start" id="start"></div>-->
						<!--<div class="layui-input-inline layui-show-xs-block">-->
						<!--<input class="layui-input" placeholder="截止日" name="end" id="end"></div>-->
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5">赛项</div>
							<select name="project" id="saixiang">
								<option value="">全部</option>
								<option v-for="match in matchList" :value="match.id">{{match.theme}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5">赛区</div>
							<select name="division" id="saiqu">
								<option value="">全部</option>
								<option v-for="zone in zoneList" :value="zone.id">{{zone.zoneName}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5">赛程</div>
							<select name="group" id="saicheng">
								<option value="">全部</option>
								<option v-for="grade in scheduleTypeList" :value="grade.id">{{grade.name}}</option>
							</select>
						</div>
						<div class="layui-input-inline layui-show-xs-block">
							<button class="layui-btn" lay-submit="" lay-filter="sreach" onclick="search()">
								<i class="layui-icon">&#xe615;</i></button>
						</div>
					</form>
				</div>
				<div class="layui-card-header">
					<!--<button class="layui-btn layui-btn-danger" onclick="delAll()">-->
						<!--<i class="layui-icon"></i>批量删除-->
					<!--</button>-->
					<!--<button class="layui-btn" onclick="xadmin.open('添加用户','./order-add.html',800,600)">-->
						<!--<i class="layui-icon"></i>添加-->
					<!--</button>-->
				</div>
				<div class="layui-card-body"  v-cloak>
					<table class="layui-table layui-form" id="table">
						<span style="float: left">共计{{total}}条数据</span>
						<div class="layui-btn-container">
							<a class="layui-btn layui-btn-sm" style="float: right;" href="https://dzxh.oss-cn-hangzhou.aliyuncs.com/excel/%E6%99%8B%E7%BA%A7.xls" target="_blank">下载模板</a>
							<button class="layui-btn layui-btn-sm" @click="bullet" style="float: right;">导入</button>
							<button class="layui-btn layui-btn-sm" onclick="quxiao()" id="gongbu1"  style="float: right;">撤销公布</button>
							<button class="layui-btn layui-btn-sm" onclick="gongbu()" id="gongbu2"  style="float: right;">公布晋级</button>
						</div>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<input type="file" id="p1" style="display:none">
</body>
<script src="./js/vue.js"></script>
<script>
var form
layui.use(['form', 'table'], function () {
	 form = layui.form
	// layer.msg('玩命卖萌中', function(){
	//   //关闭后的操作
	//   });
	//监听提交
	form.on('submit(sreach)', function (data) {
		console.log(data)
		// layer.msg(JSON.stringify(data.field), function () {
		// location.href = 'index.html'
		// })
		return false
	})
})
var sum=0
var step2
function quxiao(){
		if (confirm("是否取消晋级？")){
	var table = layui.table
 var data=table.checkStatus('table').data
 var idstring=[]
 step2=1
 sum=data.length
 for (i=0;i<data.length;i++){
	 var querydata={
		 matchId:data[i].mid,
    scheduleId:data[i].sid,
      zoneId:data[i].zid,
	 }
	 qfabu(JSON.stringify(querydata),sum)


 }
 }
	}
function qfabu(querydata,sum){
	CancelPublishPromotedTeam(JSON.parse(querydata),function(data){
		if (step2==sum){
			alert("取消晋级成功！")
			location.reload()
		}
		step2++

 })
}
function  gongbu(){
	if (confirm("是否公布晋级？")){

	var table = layui.table
 var data=table.checkStatus('table').data
 var idstring=[]
 step2=1
 var sum=data.length
 for (i=0;i<data.length;i++){
	 var querydata={
		 matchId:data[i].mid,
    scheduleId:data[i].sid,
      zoneId:data[i].zid,
	 }
	 fabu(JSON.stringify(querydata),sum)

 }
  console.log(idstring)
}

}
function fabu (querydata,sum){
	console.log(querydata)

	PublishPromotedTeamNew(JSON.parse(querydata),function(data){
          if (step2==sum){
						alert("晋级公布成功！")
						location.reload()
					}

					step2++
	})
}
	var app=new Vue({
		el: '#content',
		data: {
			scheduleTypeList:[],
			matchWorkList:[],
			gradeList:[],
			matchList:[],
			zoneList:[],
			total:0,

			list:[],
			aaa: 123,
			status:['审核','待审核' ,'通过', '不通过'],
			participate:['审核','参赛' ,'弃权' ],
			cols: [ //表头
				{type: 'checkbox', fixed: 'left',name:"xitong"},
				{field: 'index', title: '序号'},
				{field: 'matchName', title: '赛项'},
				{field: 'geScheduleName', title: '赛程'},
				{field: 'zoneName', title: '赛区'},

				{field: 'status', title: '状态' },
				{field: 'operating', title: '操作', width: 135, templet: '#operating'},
			]
		},
		methods:{
			loadGradeList:function(){
				GradequeryList({},function(data){
					app.gradeList=data
				},function(status,message){
					// alert(message)
				})
			},
			loadMatchList:function(){

				TmatchqueryList({},function(data){
					// alert(JSON.stringify(data))


					app.matchList=data;

					console.log(JSON.stringify(app.matchList))
				})
			},
			loadScheduleTypeList:function(){
				ScheduleTypequeryList({},function(data){
					app.scheduleTypeList=data;
				})
			},
			loadZoneList:function(){

				var funTool = fun_tool();
				app.zoneList=funTool.getAdminZoneIds();
				// alert(JSON.stringify(app.zoneList))
				// ZonequeryList({},function(data){
				// 	app.zoneList=data
				// },function(status,message){
				// 	alert(message);
				// })
			},
			getGradeName:function(varGradeId){
				for(var i=0; i<this.gradeList.length;++i){
					if(this.gradeList[i].id == varGradeId){
						return this.gradeList[i].gradeName;
					}
				}
				return null;
			},
			getMatchName:function(varMatchId,index){
			 // alert(varMatchId)
			 console.log(JSON.stringify(this.matchList))
				for(var i=0; i<this.matchList.length;++i){

					if(this.matchList[i].id == varMatchId){

						// alert(this.matchList[i].theme)
						return this.matchList[i].theme;
					}
				}
				return null;
			},
			getZoneName:function(varZoneId){
				for(var i=0; i<this.zoneList.length;++i){
					if(this.zoneList[i].id == varZoneId){
						// alert(this.zoneList[i].zoneName)
						return this.zoneList[i].zoneName;
					}
				}
				return null;
			},
			getScheduleName:function(varScheduleId){
				// alert(JSON.stringify(this.scheduleTypeList))
				for(var i=0; i<this.scheduleTypeList.length; ++i){
					if(this.scheduleTypeList[i].id=varScheduleId){
						return this.scheduleTypeList[i].name;
					}
				}
				return null;
			},
			getStatus:function(varState){
				//0:未发布 1:已发布,团队未确认参赛 2 确认参赛

				if(varState == 0){
					return "未发布"
				}else if (varState >= 1) {
					return "已发布"
				}
				return "未发布"
			},
			opentab:function(name,url){
				//单击事件
				console.log(name)
				console.log(url)
				xadmin.add_tab(name,url)
			},
			getData(){
				var reqObj={
					current:1,
					size:50000
				}
				this.loadMatchList();
				this.loadZoneList();
				this.loadGradeList();
				this.loadScheduleTypeList();
				 setTimeout(function(){
					 var body1={
						 "groupby": [
							"match_id",
							"schedule_id",
							"zone_id"
						]
					 }
					 ImportAdvanceViewqueryList(body1,function(data){
						//   alert(JSON.stringify(body1))
	 					app.list=data
						var list=[]
	 					for(var i=0;i<app.list.length;++i){
							//  alert(app.list[i].zoneId)

							var varItem={
								id:app.list[i].id,
								index:i,
								gradeName:app.getGradeName(app.list[i].gradeId),
								matchName:app.getMatchName(app.list[i].matchId),
								zoneName:app.getZoneName(app.list[i].zoneId),
								status:app.getStatus(app.list[i].state),
								geScheduleName:app.list[i].scheduleName,
								mid:app.list[i].matchId,
								zid:app.list[i].zoneId,
								sid:app.list[i].scheduleId,
							}
							var zoneinfo=app.getZoneName(app.list[i].zoneId)
							//  alert(zoneinfo)
								if (zoneinfo!=null){
							list.push(varItem)
						}

	 					}


								app.list=list

						app.total=app.list.length
						form.render()
						// alert(JSON.stringify(app.list))
	 				})
	 				app.init()
				 },2000)
			},
			bullet:function() {
				p1.click()
			},
			init:function() {
				var that = this
				layui.use(['laypage','table'], function () {
					// var laypage = layui.laypage;
					// //执行一个laypage实例
					// laypage.render({
					// 	elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
					// 	,count: 16 //数据总数，从服务端得到
					// });
					var table = layui.table
					//头工具栏事件
					table.render({
						elem: '#table',
						url:'',
						title: '用户数据表',
						cols: [that.cols],
						page: true,
						data: that.list
					})
				})
			}
		}
	})
	window.onload=function(){
		app.getData()
	}
</script>
<script src="./js/jquery.min.js"></script>
<script type="text/html" id="operating">
	<a href="javascript:;" onclick="parent.xadmin.open('查看晋级名单', 'examineGrade1.html?mid={{d.mid}}&zid={{d.zid}}&sid={{d.sid}}')"   class="layui-table-link">查看晋级名单</a>
</script>
<script>
	/*用户-删除*/
	function member_del(obj, text, id) {
		layer.confirm( text,
			function (index) {
				//发异步删除数据
				$(obj).parents("tr").remove()
				layer.msg('操作成功!', {
					icon: 1,
					time: 1000
				})
			})
	}

	function deleteConfirmation(status) {
		console.log(status)
		var str  = status === 1 ? '新数据覆盖原有数据' : '成绩已公布不可上传'
		layer.confirm( str,
			function yes (index) {
				//发异步删除数据
				console.log('同意')

				var index = parent.layer.getFrameIndex(window.name)
				//关闭当前frame
				parent.layer.close(index)
				// 可以对父窗口进行刷新
				xadmin.father_reload()
			},
			function cancel (index) {
				console.log('拒绝')
				//发异步删除数据
			}
		)
	}
	var baseurl="https://serviceprod.kpcb.org.cn"
	var fileInput1 = document.getElementById("p1");
	fileInput1.addEventListener('change', function(event) {
	            var filevalue = fileInput1.value;
	            var index = filevalue.lastIndexOf('.');
	            var kuozhanming=filevalue.substring(index)

	 upload_file = fileInput1.files[0];
	 if (upload_file==undefined){
	   return false
	 }
	// 或file = fileInput.files.item(0);
	var formdata = new FormData();
	formdata.append('file', upload_file);
	    url =baseurl+ '/abkj-api-match-provider/excel/importPromotedTeam'
			  var prjName="mgr_"
				// alert(localStorage.getItem(prjName+"token"))
	    $.ajax({
	  "method": "post",
	url: url,
	"headers":{
		"Authorization":localStorage.getItem(prjName+"token")
	},
	data: formdata,
	processData: false,//重要
	contentType: false,//重要
	success: function (data) {
		  // alert(JSON.stringify(data))
	   if (data.message=='success'){
			  alert("晋级名单导入成功！")
				 location.reload()
				return false
		 }
		 else {
			 alert("晋级名单导入失败！")
		 }


	}})

	}, false);
	function search(){
		// alert(JSON.stringify(app.list))
		var list=[]
		for (i=0;i<app.list.length;i++){
			var n1=app.list[i].matchName
			var n2=app.list[i].geScheduleName
			var n3=app.list[i].zoneName
			if (n3==undefined||n3==null){
				n3=''
			}
			// alert(n1)
			// alert(n2)
			// alert(n3)
			// alert(document.getElementById("saiqu").options[document.getElementById("saiqu").selectedIndex].text)
            //  alert(document.getElementById("saiqu").options[document.getElementById("saiqu").selectedIndex].text)
            //  alert(document.getElementById("saixiang").options[document.getElementById("saixiang").selectedIndex].text)
			//  alert(document.getElementById("saicheng").options[document.getElementById("saicheng").selectedIndex].text)
              var s3=document.getElementById("saiqu").options[document.getElementById("saiqu").selectedIndex].text
			  if (s3=="全部"){
				  s3=""
			  }
			  var s2=document.getElementById("saicheng").options[document.getElementById("saicheng").selectedIndex].text
			  if (s2=="全部"){
				s2=""
			  }
			  var s1=document.getElementById("saixiang").options[document.getElementById("saixiang").selectedIndex].text
			  if (s1=="全部"){
				  s1=""
			  }
			// alert(n1)
			if (n1.indexOf(s1)>-1&&n2.indexOf(s2)>-1&&n3.indexOf(s3)>-1){
				 list.push(app.list[i])
				//   alert(JSON.stringify(list))
		 }

		}

		layui.use(['laypage','table'], function () {
			// var laypage = layui.laypage;
			// //执行一个laypage实例
			// laypage.render({
			// 	elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
			// 	,count: 16 //数据总数，从服务端得到
			// });
			var table = layui.table
			//头工具栏事件
			table.render({
				elem: '#table',
				url:'',
				title: '用户数据表',
				cols: [app.cols],
				page: true,
				data: list
			})
		})
	}
	function initd1(){
		if (localStorage.sysroleId!='1'){
				document.getElementById("gongbu1").style.display='none'
					document.getElementById("gongbu2").style.display='none'
		}
	}
	initd1()
</script>

</html>
